package com.homework.demo2;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class test {
    public static void main(String[] args) {
        SchoolClass schoolClass = new SchoolClass();
        Student s1 = new Student("张三");
        s1.addCourse(new Course("语文"));
        s1.addCourse(new Course("数学"));
        s1.addCourse(new Course("英语"));

        Student s2 = new Student("李四");
        s2.addCourse(new Course("语文"));
        s2.addCourse(new Course("英语"));

        Student s3 = new Student("王五");
        s3.addCourse(new Course("数学"));
        s3.addCourse(new Course("英语"));
        
        schoolClass.addStudent(s1);
        schoolClass.addStudent(s2);
        schoolClass.addStudent(s3);

        HashMap<String,Integer> hs = new HashMap();
        HashSet<Student> students = schoolClass.getStudents();
        for (Student student:students){
            HashSet<Course> courses = student.getCourses();
            for (Course course:courses){
                Integer count= hs.get(course.getName());
                hs.put(course.getName(),count==null?1:count+1);
            }
        }
        Set<Map.Entry<String, Integer>> entries = hs.entrySet();
        for (Map.Entry entry:entries){
            System.out.println(entry.getKey()+":"+entry.getValue());
        }


    }
}
